/*
   Copyright (c) 2019 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZMindMap is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.

*/

package xuanzi.openmind.nodes;

import xuanzi.commons.graphics.Canvas;
import xuanzi.commons.graphics.BoxF;
import xuanzi.openmind.layout.Box;

public class Group extends Widget{
 
Node a,b;
private float borderSize = 3f;
float radius = 8f;
	
	public Group(Node a,Node b) {
		this.a = a;
		this.b = b;
		label = "分组";
	}
	
	public Group() {
		label = "分组";
	}
	
	
	@Override
	public void draw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.draw(canvas);
		BoxF start = a.getNodeBound();
		BoxF end = b.getNodeBound();
		{
			setEmpty();
			union(a.getNodeBound());
			union(b.getNodeBound());
			union(a.renderBuffer.childBound);
			union(b.renderBuffer.childBound);
			inset(-8, -5);
		}
		 
		{ 
			paint.fill(0x11999999);
			canvas.drawRect(this, radius, paint);
			paint.stroke(a.renderBuffer.borderColor,borderSize );
				
			canvas.drawRect(this,radius, paint);
			
			//canvas.drawRect(a.getNodeBound(), paint);
			//canvas.drawRect(b.getNodeBound(), paint);
		} 
	}
	
	
	
	@Override
	public void onLayout(Box parent) {
		setEmpty();
		union(a.getNodeBound());
		union(b.getNodeBound());
		union(a.renderBuffer.childBound);
		union(b.renderBuffer.childBound);
		super.onLayout(parent);
		System.out.println("layout "+this);
	}
	
	public void setA(Node a) {
		this.a = a;
	}
	
	public void setB(Node b) {
		this.b = b;
	}
	
	public Node getA() {
		return a;
	}
	
	public Node getB() {
		return b;
	}
}
